<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
<title>Настройки</title>
<script language="JavaScript">

function getRequestBody(oForm)
{
        var aParams = new Array();
   for(var i = 0; i < oForm.elements.length; i++)
           if ((oForm.elements[i].name != "btn_start") && (oForm.elements[i].name != "btn_close") && (oForm.elements[i].name != "btn_print") && (oForm.elements[i].name != "answer_code"))
           {
              var sParam = encodeURIComponent(oForm.elements[i].name);
                        sParam += "=";
              sParam += encodeURIComponent(oForm.elements[i].value);
                aParams.push(sParam);
                }
        return aParams.join("&");
}

function userAdd()
{
        var req = false;
        function reqComplete()
        {
                if (req.readyState == 4)
                {
                        document.form_users.btn_user_add.disabled = false;
                        if (req.status == 200)
                        {
                                alert(req.responseText);
                        }
                }
        }

        if (window.XMLHttpRequest)
                req = new XMLHttpRequest();
        else if (window.ActiveXObject)
                req = new ActiveXObject("Microsoft.XMLHTTP");

        if (req)
        {
                document.form_users.btn_user_add.disabled = true;

                req.open("POST", "/user_add?id=" + Math.random(), true);
                req.onreadystatechange = reqComplete;
                req.send(getRequestBody(document.form_users));
        }
}

function groupAdd()
{
        var req = false;
        function reqComplete()
        {
                if (req.readyState == 4)
                {
                        if (req.status == 200)
                        {
                                alert(req.responseText);
                        }
                }
        }

        if (window.XMLHttpRequest)
                req = new XMLHttpRequest();
        else if (window.ActiveXObject)
                req = new ActiveXObject("Microsoft.XMLHTTP");

        if (req)
        {
                req.open("POST", "/group_add?id=" + Math.random(), true);
                req.onreadystatechange = reqComplete;
                req.send(getRequestBody(document.form_groups));
        }
}

function changeGroup(userId, groupId)
{
    var req = false;
    function reqComplete()
    {
            if (req.readyState == 4)
            {
                    if (req.status == 200)
                    {
                            alert(req.responseText);
                    }
            }
    }

    if (window.XMLHttpRequest)
            req = new XMLHttpRequest();
    else if (window.ActiveXObject)
            req = new ActiveXObject("Microsoft.XMLHTTP");

    if (req)
    {
            req.open("POST", "/group_change?id=" + Math.random(), true);
            req.onreadystatechange = reqComplete;
            req.send("user_id=" + userId + "&group_id=" + groupId);
    }
}

function userChange()
{
        var req = false;
        function reqComplete()
        {
                if (req.readyState == 4)
                {
                        document.form_pass.btn_user_pass.disabled = false;
                        if (req.status == 200)
                        {
                                alert(req.responseText);
                        }
                }
        }

        if (window.XMLHttpRequest)
                req = new XMLHttpRequest();
        else if (window.ActiveXObject)
                req = new ActiveXObject("Microsoft.XMLHTTP");

        if (req)
        {
                document.form_pass.btn_user_pass.disabled = true;

                req.open("POST", "/user_change?id=" + Math.random(), true);
                req.onreadystatechange = reqComplete;
                req.send(getRequestBody(document.form_pass));
        }
}

</script>
</head>
<body bgcolor="white">
<center>
<h2>Админка</h2><br>
<hr width="85%"><br>
%USER_LIST%

%GROUPS_LIST%
<br><hr width="85%"><br>
<form name="form_users">
<b>Добавление пользователя:</b><br><br>
логин: <input type="text" value="" name="user_login" id="id_user_login" maxlength="15"> &nbsp; пароль: <input type="text" value="" name="user_pass" id="id_user_pass" maxlength="15"> &nbsp; &nbsp;<input type="button" value="Добавить!" id="btn_user_add" onClick="userAdd();"><br><br>
</form>
<br><hr width="85%"><br>
<form name="form_groups">
<b>Добавление группы:</b><br><br>
Название: <input type="text" value="" name="group_name" id="id_group_name" maxlength="15"> &nbsp; &nbsp;<input type="button" value="Добавить!" id="btn_group_add" onClick="groupAdd();"><br><br>
</form>
<br><hr width="85%"><br>
<form name="form_pass">
<b>Изменение пароля пользователя:</b><br><br>
логин: <input type="text" value="" name="user_login" id="id_user_login" maxlength="15"> &nbsp; новый пароль: <input type="text" value="" name="user_pass" id="id_user_pass" maxlength="15">
<input type="button" value="Изменить!" id="btn_user_pass" onClick="userChange();"><br>
</form>
<br><hr width="85%">
</center>
</body>
</html>

